<?php 

namespace app\index\model;

use think\Model;

class Category extends Model
{
    // protected $autoWriteTimestamp = 'datetime';

    public function Pipeline()
    {
        return $this->belongsTo('Pipeline','pipeline_id', 'id');
    }

    public static function get_cate_id()
    {
        $get_id = Project::get_project_id();
        $get_pip = Pipeline::get_pipeline_id($get_id) ;
        $get_cate = self::where(['category_name'=>input('category_name'),'pipeline_id' =>$get_pip['id']])->field('id')->find() ;
        
        if (isset($get_cate['id'])){
            return [1 ,array('category_id' => $get_cate['id'], )];
        }else{
            return [0 , "not found"];
        }  
    }

    public static function get_category_id($data='')
    {
        return self::where(['category_name'=>input('category_name'),'pipeline_id' =>$data['id']])->field('id')->find() ;
    }

    public static function get_data($data='')
    {
        return self::select($data);
    }

    public static function get_count($data='')
    {
        return self::where($data)->count();
    }

    public static function add_data($data)
    {
        return self::insert($data);
    }

    public static function update_data($data)
    {
        return self::update($data);
    }

     public static function delete_data($data='')
    {
        return self::where($data)->delete();
    }
    
}


